using PrismNavigationFramework.Infrastructure;
using PrismNavigationFramework.MVVM;

namespace HomeModule.Shell
{
    public class ShellViewModel : ViewModel<ShellView>
    {
        private readonly IPrismModuleLoadingService _prismModuleLoadingService;

        public ShellViewModel(IPrismModuleLoadingService prismModuleLoadingService)
        {
            _prismModuleLoadingService = prismModuleLoadingService;
            _prismModuleLoadingService.ModuleDownloadStateChanged += this.OnModuleDownloadStateChanged;
            this.WeAreLoadingModule = false;
        }

        protected override void OnViewLoaded()
        {
            base.OnViewLoaded();
            this.OnPropertyChanged("WeAreLoadingModule");
        }

        private void OnModuleDownloadStateChanged(object sender, ModuleDownloadStateChangedEventArgs e)
        {
            this.WeAreLoadingModule = e.ModuleDownloadStatus == ModuleDownloadStatus.StartingDownload;    
        }


        private bool _weAreLoadingModule;
        public bool WeAreLoadingModule
        {
            get { return _weAreLoadingModule; }
            set 
            { 
                _weAreLoadingModule = value;
                this.OnPropertyChanged("WeAreLoadingModule");           
            }
        }
    }
}